<?php
namespace App\Admin\Models;
use Common\BaseModel;
class AdminRule extends BaseModel
{
    protected $res;
    protected $redis_key="admin_";
    public function getSource()
    {
        return "f_admin_rule";
    }
    public function initialize()
    {
        parent::initialize();
    }


    public function rule_list($ids=''){
        if($ids) {
            $conditions = "id in('{$ids}') and is_show=0";
        }else{
            $conditions = "is_show=0";
        }
        $rulelist = $this::find(
            array(
                $conditions,
            )
        )->toarray();
        return $rulelist;
    }



    public function rulelist($ids){
        if($ids) {
            $conditions = "id in({$ids}) and is_show=0";
        }else{
            $conditions = "is_show=0";
        }
        $rulelist = $this::find(
            array(
                $conditions,
                "columns"=>'rule',
            )
        )->toarray();
        $new_rulelist=[];
        foreach($rulelist as $key=>$value){
            $new_rulelist[$key]=$value['rule'];
        }
        return $new_rulelist;
    }


    /**
     * @param $id
     * @return array
     */
    public function find_by_id($id){
        if(empty($id)){
            return [];
        }
        $cate_info = $this->findFirstById($id);
        if($cate_info){
            return $cate_info->toarray();
        }else{
            return [];
        }
    }


    public function rule_save($params){
        $result = $this::save($params);
        if($result){
            return true;
        }else{
            return false;
        }
    }

}
